package com.lemon.smartsafetynew.ui.adapter.contact;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTNewClickListener;
import com.lemon.smartsafetynew.entity.contact.PersonVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/11/10.
 */

public class LabelListAdapter extends LemonRcvAdapter<PersonVo> {

    private RecyclerTNewClickListener<PersonVo> mListener;

    public LabelListAdapter(@Nullable List<PersonVo> data,
                            RecyclerTNewClickListener<PersonVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<PersonVo> {

        private PersonVo mData;
        private int mPosition;

        @Bind(R.id.department_tv)
        TextView departmentTv;
        @Bind(R.id.department_layout)
        LinearLayout departmentLayout;
        @Bind(R.id.right_arrow)
        ImageView rightArrow;

        @Override
        public int getLayoutResId() {
            return R.layout.item_department_textview;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            departmentLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClickNew(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(PersonVo personVo, int position) {

            mData = personVo;
            mPosition = position;

            departmentTv.setText(CommonUtil.avoidNullString(personVo.getUser_name()));

            if (mDataList.size() - 1 == position) {
                rightArrow.setVisibility(View.GONE);
            } else {
                rightArrow.setVisibility(View.VISIBLE);
            }

        }
    }
}
